package be.xios.ti.droodle;

import java.awt.event.*;

/**
 * De acties die moeten ondernomen worden om een Circle te tekenen
 * 
 * @author Kris Hermans
 */
public class CircleDrawAction extends ShapeDrawAction {
	private CircleShape cShape;
	
	/**
	 * @param drawing
	 * @param panel
	 */
	protected CircleDrawAction(ShapeJPanel panel) {
		super(panel);
	}

	/* (non-Javadoc)
	 * @see be.hogelimb.ti.droodle.ShapeDrawAction#click(java.awt.event.MouseEvent)
	 */
	public void doClick(MouseEvent e) {
		switch (getClickCount()) {
			case 1: shape = new CircleShape();
					cShape = (CircleShape)shape;
					cShape.setX(e.getX());
					cShape.setY(e.getY());
					cShape.setColor(panel.getForeground());
					cShape.setSize(panel.getPenSize());
					break;
			
			case 2: int dy = Math.abs(e.getY() - cShape.getY());
					int dx = Math.abs(e.getX() - cShape.getX());
					double r = Math.sqrt(Math.pow(dx,2)+Math.pow(dy,2));
					cShape.setRadius((int)r);
					ready();
					setClickCount(0);
					break;
					
			default: System.err.println("niet mogelijk");
		}
	}

}
